<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>后台管理_编辑学校图片</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/uploadify.css">
    <script src="/js/jquery.uploadify.min.js" type="text/javascript"></script>
</head>
<body>
<script language="JavaScript">
    $(function() {
        $('#file_upload').uploadify({
            'buttonText'  : '上传图片',
            'fileObjName' : 'file',
            'formData'     : {'schoolId':'${schoolId}'},
            'fileTypeDesc' : 'image Files',
            'fileTypeExts' : '*.gif;*.jpg;*.png;*.bmp',
            'swf'      : '/js/uploadify.swf',
            'uploader' : '/uploadSchoolPic.do',
            'onUploadSuccess' : function(file, data, response) {
                var ret =  eval("("+data+")");
                var img = document.createElement("img");
                if(ret["error"]==1)
                {
                    alert(ret["message"]);
                    return;
                }
                var id = ret["id"];
                $(img).attr("src", "/"+ret.url);
                var btn = document.createElement("button");
                $(btn).text("删除").addClass("btn btn-link");
                $(btn).click(function(){
                    $.post("/man/school/pictures/delete",{id:id});
                    $(this).parent().remove();
                });
                $("<li class=\"list-group-item\"></li>").append(img,btn).appendTo($("ul"));

            },
            'onUploadError' : function(file, errorCode, errorMsg, errorString) {
                alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
            }
        });
    });
   function delPic(obj,id){
       $.post("/man/school/pictures/delete",{id:id},function(result){
           $(obj).parent().remove();
       })
   }
</script>
<div class="container" >
    <div class="form-group text-left">
        <input id="file_upload" name="file_upload" type="file" multiple="flase">
    </div>
    <ul class="list-group">
         <c:forEach items="${list}" var="pic">
             <li class="list-group-item"><img src="${pic.url}"><button class="btn btn-link" onclick="delPic(this,${pic.id})">删除</button></li>
         </c:forEach>
    </ul>
</div>

</body>
</html>